﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using HomeBuyerTools.ViewModels;
using System.Xml.Linq;
using HomeBuyerTools.FinanceProperties;
using MyToolkit.Multimedia;
using System.ComponentModel;

namespace HomeBuyerTools.Views
{
    public partial class Help : PhoneApplicationPage
    {
        public Help()
        {
            InitializeComponent();
            Loaded += Help_Loaded;
        }

        void Help_Loaded(object sender, RoutedEventArgs e)
        {
            LayoutRoot.Background = Custom.getPivotBackground();

            var xdoc = XDocument.Load(@"XmlData\Help.xml");

            var findEle = from i in xdoc.Descendants("de") where i.Attribute("id").Value.ToString() ==App.Helpid.ToString() select i;
            List<HelpMenu> HelpItemList = new List<HelpMenu>();
            foreach (var n in findEle.Descendants("c"))
            {
               // tblkVideosTitle.Text = n.Attribute("title").Value;

                break;
            }
            foreach (var d in findEle.Descendants("c").Elements("des"))
            {
               HelpMenu HelpItem = new HelpMenu();

                HelpItem.des = d.Value;
                HelpItemList.Add(HelpItem);
            }


            ListHelp.ItemsSource= HelpItemList;
        }
            

        

        private void imgTitle_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {

        }

        private void ListHelpMenu_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {

        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {

                YouTube.CancelPlay();
            }
            catch (Exception ex)
            {
            }

        }
        protected override void OnBackKeyPress(CancelEventArgs e)
        {
            try
            {
                if (YouTube.CancelPlay())
                    e.Cancel = true;
                else
                {

                }
                base.OnBackKeyPress(e);
            }
            catch (Exception ex)
            {
            }
        }
        private void ApplicationBarIconButton_youtube_Click(object sender, EventArgs e)
        {
            try
            {

                YouTube.LoadYoutubeVideo(App.Helpurl);
            }
            catch (Exception ex)
            {
            }
        }
    }
}